package com.lh.service.impl;

import com.lh.commonutils.R;
import com.lh.entity.EduVideo;
import com.lh.dao.EduVideoMapper;
import com.lh.feign.VodFeign;
import com.lh.service.IEduVideoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;

/**
 * <p>
 * 课程视频 服务实现类
 * </p>
 *
 * @author yms
 * @since 2021-06-05
 */
@Service
public class EduVideoServiceImpl extends ServiceImpl<EduVideoMapper, EduVideo> implements IEduVideoService {

    @Resource
    private EduVideoMapper videoMapper;

    @Resource
    private VodFeign vodFeign;

    /**
     * 删除小节
     *
     * @param id
     * @return
     */
    @Override
    public R deleteVideo(String id) {

        EduVideo eduVideo = videoMapper.selectById(id);
        String videoSourceId = eduVideo.getVideoSourceId();
        if (!StringUtils.isEmpty(videoSourceId)){
            vodFeign.removeALYVideo(videoSourceId);
        }
        int i = videoMapper.deleteById(id);
        if (i>0){
            return R.ok();
        }else {
            return R.error();
        }
    }
}
